﻿using EasyERP_BLL;
using EasyERP_BLL.Base;
using EasyERP_Model;
using EasyERP_View.FrmBase;
using System;
using System.Data;
using System.Windows.Forms;

namespace EasyERP_View.POP
{
    /// <summary>
    /// 主代码参照窗体
    /// </summary>
    public partial class FrmPopMajor : Form
    {
        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        public FrmPopMajor()
        {
            InitializeComponent();
        }
        #endregion

        #region 窗体加载事件
        /// <summary>
        /// 窗体加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmPopMajor_Load(object sender, EventArgs e)
        {
            Query();
        }
        #endregion

        #region 单击查询按钮事件
        /// <summary>
        /// 单击查询按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSearch_Click(object sender, EventArgs e)
        {
            Query();
        }
        #endregion

        #region 单击主代码编号文本框垃圾桶图标事件
        /// <summary>
        /// 单击主代码编号文本框垃圾桶图标事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnClearMajor_cd_Click(object sender, EventArgs e)
        {
            TxtMajor_cd.Clear();
        }
        #endregion

        #region 单击主代码名称文本框垃圾桶图标事件
        /// <summary>
        /// 单击主代码名称文本框垃圾桶图标事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnClearMajor_nm_Click(object sender, EventArgs e)
        {
            TxtMajor_nm.Clear();
        }
        #endregion

        #region 双击单元格任意行事件
        /// <summary>
        /// 双击单元格任意行事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DGView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
            {
                FrmMinor.major_cd = DGView["major_cd", e.RowIndex].Value.ToString();
                FrmMinor.major_nm = DGView["major_nm", e.RowIndex].Value.ToString();
                Close();
            }
        }
        #endregion

        #region 主代码查询方法
        /// <summary>
        /// 主代码查询方法
        /// </summary>
        private void Query()
        {
            B_Major_BLL Major_BLL = new B_Major_BLL();

            //数据封装
            B_Major model = new B_Major
            {
                major_cd = TxtMajor_cd.Text.Trim(),
                major_nm = TxtMajor_nm.Text.Trim()
            };

            DataTable dt = Major_BLL.Get_B_Major(model);

            //绑定DataGridView
            DGView.DataSource = dt;

            if (dt.Rows.Count == 0)
            {
                B_Message_BLL.MessageCaveat("1004");
            }
        }
        #endregion
    }
}
